<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>Dipole Point Source In A Homogeneous Propagation Medium Example (k-Wave)</title>
	<link rel="stylesheet" href="kwavehelpstyle.css" type="text/css">
	<meta name="description" content="Dipole Point Source In A Homogeneous Propagation Medium Example.">
</head>

<body>
<div class="content">

<h1>Dipole Point Source In A Homogeneous Propagation Medium Example</h1>

<p>This example provides a simple demonstration of using k-Wave for the simulation and detection of a time varying pressure dipole source within a two-dimensional homogeneous propagation medium. It builds on the <a href="example_tvsp_homogeneous_medium_monopole.html">Monopole Point Source In A Homogeneous Propagation Medium Example</a>.</p>

<p>
    <ul>
        <li><a href="matlab:edit([getkWavePath('examples') 'example_tvsp_homogeneous_medium_dipole.m']);" target="_top">Open the file in the MATLAB Editor</a></li>
        <li><a href="matlab:run([getkWavePath('examples') 'example_tvsp_homogeneous_medium_dipole']);" target="_top">Run the file in MATLAB</a></li>
    </ul>
</p>

<h2>Contents</h2>
<div>
	<ul>
        <li><a href="#heading1">Defining the time varying velocity source</a></li>
        <li><a href="#heading2">Running the simulation</a></li>
    </ul>
</div>	

<a name="heading1"></a>
<h2>Defining the time varying velocity source</h2>

<p>A time varying velocity source is defined analogous to the time varying pressure source encountered in the previous example. A binary matrix (i.e., a matrix of 1's and 0's with the same dimensions as the computational grid) is assigned to <code>source.u_mask</code>, where the 1's represent the grid points that form part of the source. The time varying input signal is then assigned to <code>source.ux</code> and <code>source.uy</code>. These can be defined independently, and may be a single time series (in which case the same time series is applied to all source points), or a matrix of time series following the source points using MATLAB's column-wise linear matrix index ordering.</p>

<p>In this example, a dipole is created by assigning a sinusoidal velocity input to a single source point. The input is filtered using <code><a href="filterTimeSeries.html">filterTimeSeries</a></code> to remove any high-frequency components not supported by the grid.</p>

<pre class="codeinput">
<span class="comment">% define a single source point</span>
source.u_mask = zeros(Nx, Ny);
source.u_mask(end - Nx/4, Ny/2) = 1;

<span class="comment">% define a time varying sinusoidal velocity source in the x-direction</span>
source_freq = 0.25e6;       <span class="comment">% [Hz]</span>
source_mag = 2 / (medium.sound_speed * medium.density);
source.ux = -source_mag * sin(2 * pi * source_freq * kgrid.t_array);

<span class="comment">% filter the source to remove high frequencies not supported by the grid</span>
source.ux = filterTimeSeries(kgrid, medium, source.ux);
</pre>

<p>Note, an acoustic dipole can also be created using a pressure source comprising of two adjacent grid points with their inputs out-of-phase. Higher order source patterns can similarly be created using combinations of pressure or velocity sources.</p>

<a name="heading2"></a>
<h2>Running the simulation</h2>

<p>A plot of the input time series driving the source along with the acoustic pressure recorded at the sensor point is given below. The magnitude of the velocity input is scaled by the impedance of the medium, so the magnitude of the pressure recorded at the sensor is the same as in the previous example. The final pressure field within the computational domain is also returned by setting <code>sensor.record</code> to <code>{'p', 'p_final'}</code>.</p>

<img vspace="5" hspace="5" src="images/example_tvsp_homogeneous_medium_dipole_01.png" style="width:560px;height:420px;" alt="">
<img vspace="5" hspace="5" src="images/example_tvsp_homogeneous_medium_dipole_02.png" style="width:560px;height:420px;" alt="">

</div></body></html>